// Tags: DP
#include <algorithm>
#include <cstdio>

const int N = 1e5 + 5;
int top, n, stk[N], a[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("LIS.in", "r", stdin);
  freopen("LIS.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  stk[++top] = a[1];
  for (int i = 2, pos; i <= n; ++i) {
    if (a[i] > stk[top])
      stk[++top] = a[i];
    else {
      pos = std::lower_bound(stk + 1, stk + top + 1, a[i]) - stk;
      stk[pos] = a[i];
    }
  }
  printf("%d", top);
  return 0;
}